package com.ruoyi.payment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.payment.domain.SalaryPaymentVO;
import com.ruoyi.slip.service.ISalarySlipService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.payment.domain.SalaryPayment;
import com.ruoyi.payment.service.ISalaryPaymentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工资发放记录Controller
 * 
 * @author cxs
 * @date 2025-05-31
 */
@RestController
@RequestMapping("/payment/payment")
public class SalaryPaymentController extends BaseController
{
    @Autowired
    private ISalaryPaymentService salaryPaymentService;

    @Autowired
    private ISalarySlipService salarySlipService;





    /**
     * 查询工资发放记录列表
     */
    @PreAuthorize("@ss.hasPermi('payment:payment:list')")
    @GetMapping("/list")
    public TableDataInfo list(SalaryPayment salaryPayment)
    {
        startPage();
        List<SalaryPaymentVO> list = salaryPaymentService.selectSalaryPaymentList(salaryPayment);
        return getDataTable(list);
    }

    /**
     * 导出工资发放记录列表
     */
    @PreAuthorize("@ss.hasPermi('payment:payment:export')")
    @Log(title = "工资发放记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SalaryPayment salaryPayment)
    {
//        List<SalaryPayment> list = salaryPaymentService.selectSalaryPaymentList(salaryPayment);
        ExcelUtil<SalaryPayment> util = new ExcelUtil<SalaryPayment>(SalaryPayment.class);
//        util.exportExcel(response, list, "工资发放记录数据");
    }

    /**
     * 获取工资发放记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('payment:payment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(salaryPaymentService.selectSalaryPaymentById(id));
    }

    /**
     * 新增工资发放记录
     */
    @PreAuthorize("@ss.hasPermi('payment:payment:add')")
    @Log(title = "工资发放记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SalaryPayment salaryPayment)
    {
        return toAjax(salaryPaymentService.insertSalaryPayment(salaryPayment));
    }

    /**
     * 修改工资发放记录
     */
    @PreAuthorize("@ss.hasPermi('payment:payment:edit')")
    @Log(title = "工资发放记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SalaryPayment salaryPayment)
    {
        return toAjax(salaryPaymentService.updateSalaryPayment(salaryPayment));
    }

    /**
     * 删除工资发放记录
     */
    @PreAuthorize("@ss.hasPermi('payment:payment:remove')")
    @Log(title = "工资发放记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(salaryPaymentService.deleteSalaryPaymentByIds(ids));
    }

    /**
     * 查看工资条
     */
     @PreAuthorize("@ss.hasPermi('payment:payment:slip')")
     @GetMapping("/slip/{id}")
      public AjaxResult slip(@PathVariable Long id){
         return success(salaryPaymentService.selectSlip(id));
     }
}
